package com.fun.feifun.base.utils;

import com.fun.feifun.modules.business.model.BusinessGoods;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ControlUtils {
	//resource的路径
	public final static String resourcePath = ClassUtils.getDefaultClassLoader().getResource("").getPath();

    /**
     * 判断字符串是否为空
     * @param str
     * @return
     */
    public static boolean isNotEmpty(String str){
        if(str!=null&&str!=""){
            return true;
        }
        return false;
    }

    public static boolean isNotEmpty(Collection list){
        if(!CollectionUtils.isEmpty(list)){
            return true;
        }
        return false;
    }

    /**
     * 判断是否为空
     * @param item
     * @return
     */
    public static boolean isNotEmpty(Integer item){
        if(item!=null&&item!=0){
            return true;
        }
        return false;
    }

    /**
     * 判断是否为空
     * @param id
     * @return
     */
    public static boolean isNotEmpty(Long id){
        if(id!=null&&id!=0l){
            return true;
        }
        return false;
    }

    public static  <T>  Map<T,T>  ListToMap(Map<T, List<T>> mapList){
        Map<T,T> reMap=new HashMap();
        mapList.forEach((key,value)->{
            T t = value.get(0);
            reMap.put(key,t);
        });
        return reMap;
    }


    /**
     * 驼峰转下划线
     * @param camelCaseString
     * @return
     */
    public static String convertToUnderscore(String camelCaseString) {
        if (StringUtils.isBlank(camelCaseString)) {
            return camelCaseString;
        }
        return camelCaseString.replaceAll(
                "([a-z])([A-Z]+)",
                "$1_$2"
        ).toLowerCase();
    }

}
